<?

class osLinux extends osGeneric {
	public $id = 'linux';

	public $device;
	public $tabs = array(
		'system' => 'System',
		'ipstats' => 'IP Statistics',
		'interfaces' => 'Ports',
		'processes' => 'Processes'
	
	);	
	public $snmpSections = array(
		'HOST-RESOURCES-MIB',
		'IF-MIB',
		'SNMPv2-MIB'
	);
	public $dataCollectors = array(
		'getProcessorLoads',
		'getProcessorUsage',
		'getMemoryUsed',
		'getMemoryUsage',
		'getStorageUsage',
		'getSystemLoad',
		'getIPStatistics',
		'getNetStatistics',
		'setProcessesUsersUptimeRrd'
	);
	
	public function __construct(&$device=null) { $this->device = $device; }
	
	public function getResources() {
		// Device Information
		foreach ($this->device->snmp->find('HOST-RESOURCES-MIB','^hrDeviceIndex') AS $key=>$index) {
			$item = $this->device->snmp->find('HOST-RESOURCES-MIB','hrDevice([a-zA-z0-9]+).'.$index,true);
			$item = $item[$index];			
			switch (substr($item['hrDeviceType'],strrpos(':',$item['hrDeviceType']))) {
				case 'hrDeviceProcessor':
					$item['hrProcessorLoad'] = $this->device->snmp->get('HOST-RESOURCES-MIB','hrProcessorLoad.'.$index);
					$this->device->cpus[]  = new objProcessor($item);
					break;
			}
		}
		
		// Storage/Memory Information
		foreach ($this->device->snmp->find('HOST-RESOURCES-MIB','^hrStorageIndex') AS $key=>$index) {
			$item = $this->device->snmp->find('HOST-RESOURCES-MIB','^hrStorage([a-zA-z0-9]+).'.$index,true);
			$item = $item[$index];
			switch (substr($item['hrStorageType'],strrpos(':',$item['hrStorageType']))) {
				case 'hrStorageRam':
				case 'hrStorageVirtualMemory':
					$this->device->memory[$index] = new objMemory($item);
					break;
				case 'hrStorageFixedDisk':
					$this->device->storage[$index] = new objStorage($item);
					break;
					
			}
		}
		// Network Interface Information
		foreach ($this->device->snmp->find('IF-MIB','^ifIndex.([0-9]+)') AS $key=>$index) {
			$item = $this->device->snmp->find('IF-MIB','^if([a-zA-z0-9]+).'.$index,true);
			$item = $item[$index];
			$item['device_id'] = $this->device->id;
			$interface = new objInterface($item);
			$this->device->interfaces[$index] = $interface;
		}	
	}
	public function getUptime() { return $this->device->snmp->get('HOST-RESOURCES-MIB','hrSystemUptime.0');}
	public function checkDescription($sysDescr='') { return preg_match("/Linux/", $sysDescr)?$this->id:'';}	
	public function getType() { return $this->device->os_type; }
	public function getDescription() { 
		$descr = explode(' ',$this->device->snmp->get('SNMPv2-MIB','sysDescr.0'));
		$output = array();
		$output[] = 'Linux Generic - '.$descr[sizeof($descr)-1];
		$output[] = 'Kernel: '.$descr[2];
		return implode('<br/>',$output);
	}
	
	
}


?>